﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using Rison.BusinessFacade.Common;
using Rison.DataAccess.Data.Biz;
using Rison.DataAccess.Common;
using Rison.BusinessFacade.Helper;
using Rison.BusinessFacade.Entity.Biz;

namespace Rison.BusinessFacade.Facade.Biz
{

    public sealed class InfosReaderFacade : FacadeBase
    {
        private string _newsCategory = "gg,zxzl,zspy,jfdt,jfhc,jftp";//公告、专项治理、站所评议、纠风动态、纠风荟萃、纠风图片
        private string _suqiuCategory = "zxsq,zxhf,hfqk";//最新诉求、最新回复、回复情况,

        private string _category = string.Empty;

        private InfosReaderFacade() { }

        public InfosReaderFacade(string infoCategory)
        {
            _category = infoCategory;
        }

        protected override DataAccessBase dbObject
        {
            get
            {
                if (dbHelper == null)
                {
                    if (_newsCategory.IndexOf(_category.ToLower()) >= 0)
                        dbHelper = new InfosReaderDb(GlobalParams.Instance.NewsConnectionString);
                    else if (_suqiuCategory.IndexOf(_category.ToLower()) >= 0)
                        dbHelper = new InfosReaderDb(GlobalParams.Instance.WYSQConnectionString);
                }

                return dbHelper;
            }
        }

        protected override string identityFieldName
        {
            get { return "RDID"; }
        }


        protected override List<SqlField> GetSqlFieldCollection(object value, bool getIdentityField)
        {
            throw new NotImplementedException();
        }

        protected override object SetPropertiesValue(DataRow row)
        {
            throw new NotImplementedException();
        }


        public bool IsNewsCategory
        {
            get { return (_newsCategory.IndexOf(_category.ToLower()) >= 0); }
        }


        //--Titel：标题
        //--Content：正文
        //--ShowTime：信息前台显示时间
        //select title,Content,ShowTime from vwInfoCategory -- content 正文字段在此视图中不存在，用ContentNoHTML字段？
        //where CategoryID=''     -- 栏目字段（需要确认）
        //Order by BackInt,ShowTime DESC,CreateTime DESC   --查询条件


        public DataRow ReadInfomation(string infoId)
        {
            return (dbObject as InfosReaderDb).ReadInfomation(infoId);
        }

        public DataSet ReadNewsInfos()
        {
            return ReadNewsInfos(-1);
        }

        public DataSet ReadNewsInfos(int subjectLength)
        {
            return ReadNewsInfos(-1, subjectLength, false);
        }

        public DataSet ReadNewsInfos(int topNum, int subjectLength, bool containContent)
        {
            if (_category.Equals("jftp"))//纠风图片 
                return (dbObject as InfosReaderDb).ReadNewsInfos(GlobalParams.Instance.InfoCategoryIds[_category], topNum, subjectLength, containContent, "(MediaFileName is not null and 0<len(MediaFileName))");
            else
                return (dbObject as InfosReaderDb).ReadNewsInfos(GlobalParams.Instance.InfoCategoryIds[_category], topNum, subjectLength, containContent);
        }

        /// <summary>
        /// 读取诉求具体内容
        /// </summary>
        /// <param name="requestId"></param>
        /// <returns></returns>
        public DataRow ReadSuqiuDetail(string requestId)
        {
            return (dbObject as InfosReaderDb).ReadSuqiuDetail(requestId);
        }

        public DataSet ReadSuqiuInfos()
        {
            return ReadSuqiuInfos(-1, -1);
        }

        public DataSet ReadSuqiuInfos(int subjectLength)
        {
            return ReadSuqiuInfos(-1, subjectLength);
        }

        public DataSet ReadSuqiuInfos(int topNum, int subjectLength)
        {
            return (dbObject as InfosReaderDb).ReadSuqiuInfos(topNum, subjectLength);
        }

         //诉求的最新回复
        public DataSet ReadSuqiuRepeat(int topNum, int subjectLength)
        {
            return (dbObject as InfosReaderDb).ReadSuqiuRepeat(topNum, subjectLength);
        }

        //获取调查内容
        public DataSet ReadVoteAnswer(string id)
        {
            return (dbObject as InfosReaderDb).ReadVoteAnswer(id);
        }

        //获得诉求list表
        public DataSet ReadSuqiuList(string condition)
        {
            return (dbObject as InfosReaderDb).ReadSuqiuList(condition);
        }

        //获取回复记录
        public DataSet SuQiuTJ()
        {
            return (dbObject as InfosReaderDb).SuQiuTJ();
        }

        public DataSet SuQiuTJ_show(int topNum, int subjectLength)
        {
            return (dbObject as InfosReaderDb).SuQiuTJ_show(topNum, subjectLength);
        }

    }
}